package com.ybkj.o2o.zhuanche.manager.impl;

import com.ybkj.o2o.zhuanche.common.DataGrid;
import com.ybkj.o2o.zhuanche.common.query.OrderRefuseQuery;
import com.ybkj.o2o.zhuanche.entity.OrderRefuse;
import com.ybkj.o2o.zhuanche.manager.OrderRefuseManager;
import com.ybkj.o2o.zhuanche.service.OrderRefuseService;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DefaultOrderRefuseManager implements OrderRefuseManager {
  @Autowired
  private OrderRefuseService orderRefuseService;

  @Override
  public DataGrid<OrderRefuse> findAll(int page, int rows) {
    int offset = (page - 1) * rows;
    RowBounds rowBounds = new RowBounds(offset, rows);

    List<OrderRefuse> list = orderRefuseService.findAll(rowBounds);
    long count = orderRefuseService.count();

    DataGrid<OrderRefuse> dataGrid = new DataGrid<>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);
    return dataGrid;
  }

  @Override
  public DataGrid<OrderRefuse> findByParam(OrderRefuseQuery orderRefuseQuery) {
    List<OrderRefuse> list = orderRefuseService.findByParam(orderRefuseQuery);
    
    Long count = orderRefuseService.countByParam(orderRefuseQuery);

    DataGrid<OrderRefuse> dataGrid = new DataGrid<>();
    dataGrid.setRows(list);
    dataGrid.setTotal(count);

    return dataGrid;
  }

}
